package wangjg.mda.model.obj;

import java.util.LinkedHashMap;
import java.util.Map;

public class ModelField implements Element {
	private String name;
	private String type;
	private String label;
	private String description;
	
	private String defaultValue;
	private Integer length;
	
	private Boolean nullable;
	private Boolean unique;
	private Boolean id;
	private Boolean auto;
	private Boolean version;
	private Boolean isTransient;
	
	private Reference reference;
	private Map attributes;
	
	public ModelField() {
	}

	public Boolean getTransient() {
		return isTransient;
	}

	public void setTransient(Boolean isTransient) {
		this.isTransient = isTransient;
	}

	public Integer getLength() {
		return length;
	}

	public void setLength(Integer length) {
		this.length = length;
	}

	public Boolean getNullable() {
		return nullable;
	}

	public void setNullable(Boolean nullable) {
		this.nullable = nullable;
	}

	public Boolean getUnique() {
		return unique;
	}

	public void setUnique(Boolean unique) {
		this.unique = unique;
	}

	public Boolean getId() {
		return id;
	}

	public void setId(Boolean id) {
		this.id = id;
	}

	public Boolean getAuto() {
		return auto;
	}

	public void setAuto(Boolean auto) {
		this.auto = auto;
	}

	public Boolean getVersion() {
		return version;
	}

	public void setVersion(Boolean version) {
		this.version = version;
	}

	@Override
	public String toString() {
		return "\n\tModelField ["
				+ ", name=" + getName()
				+ ", label=" + getLabel() 
				+ ", type=" + getType()
				+ ", length=" + length
				+ ", nullable=" + nullable 
				+ ", unique=" + unique
				+ ", defaultvalue=" + getDefaultValue() 
				+ ", description=" + getDescription()
				+ ", id=" + id 
				+ ", auto=" + auto 
				+ ", version=" + version 
				+ ",isTransient=" + isTransient
				
				+ ", reference=" + getReference()
				+ ", \n\t\tattributes=" + getAttributes() 
				+ "\n\t]";
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public Boolean getIsTransient() {
		return isTransient;
	}

	public void setIsTransient(Boolean isTransient) {
		this.isTransient = isTransient;
	}

	public Reference getReference() {
		return reference;
	}

	public void setReference(Reference reference) {
		this.reference = reference;
	}

	public Map getAttributes() {
		return attributes;
	}

	public void setAttributes(Map attributes) {
		this.attributes = attributes;
	}
	
	public Object getAttribute(String key){
		if(this.attributes==null){
			return null;
		}
		return this.attributes.get(key);
	}

	public void setAttribute(String key, Object value){
		if(value==null){
			return ;
		}
		if(this.attributes==null){
			this.attributes = new LinkedHashMap();
		}
		this.attributes.put(key, value);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((name == null) ? 0 : name.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		ModelField other = (ModelField) obj;
		if (name == null) {
			if (other.name != null)
				return false;
		} else if (!name.equals(other.name))
			return false;
		return true;
	}
}
